<template>
  <section id="pending">
    <div class="table">
      <table>
        <thead>
          <tr>
            <th>时间</th>
            <th>产品</th>
            <th>手数 (方向)</th>
            <th>挂单价格</th>
            <th>当前买/卖价格</th>
            <th>有效期</th>
            <th>止盈</th>
            <th>止损</th>
            <th>订单号</th>
            <th>操作</th>
          </tr>
        </thead>
        <tbody v-if="maxSearchDataList&&maxSearchDataList.length">
          <tr v-for="(item,index) in maxSearchDataList" :key="index">
            <td>{{$js.timeToDate(item.create_time)}}</td>
            <td>{{item.goods_name}}</td>
            <td>{{item.num}}手 / {{item.buy_type==1?'买入':'卖出'}}</td>
            <td>{{item.price}}</td>
            <td :class="{red:item.zfType==1,green:item.zfType==2}">{{item.new_price}}</td>
            <td>当周有效</td>
            <td>{{item.profit_price}}</td>
            <td>{{item.loss_price}}</td>
            <td>{{item.order_id}}</td>
            <td>
              <span @click="cdMethod(item)">撤单</span>
               <span @click="goDetail(item.system_code,item)">图表</span>
            </td>
          </tr>
        </tbody>
      </table>
      <base-nodata v-if="!(maxSearchDataList&&maxSearchDataList.length)"></base-nodata>
    </div>
   
    <base-alert :type="17" text="撤单" :bol.sync="alertBol"  smallText="您确定需要取消该订单吗？" @active="setCancellations"></base-alert>
  </section>
</template>
<script>
import { _getgzOrder,_getcxOrder } from "../../axios/index.js";
export default {
  data() {
    return {
      alertBol:false,
      typeList: [
        {
          value: 0,
          label: "全部"
        },
        {
          value: 1,
          label: "外汇"
        },
        {
          value: 2,
          label: "商品"
        },
        {
          value: 3,
          label: "指数"
        },
        {
          value: 4,
          label: "数字货币"
        }
      ],
    
      modelType: "",
      dirList: [
        {
          value: 0,
          label: "买入"
        },
        {
          value: 1,
          label: "卖出"
        }
      ],
      modelDire: "",
      dateArea: null,
      nodataListBol: false, //暂无数据
      curCDorderId: -1 //撤单id
    };
  },
  
  computed: {
    user() {
      //是否登录
      var user = this.$store.state.user;
    
      return user;
    },
    //挂单最终数据
    maxGdDataList() {
      return this.$js.maxGdDataList();
    },
    //挂单最终搜索数据
    maxSearchDataList(){
      let _searchData=[];
      var _searchDataVal=this.searchData;
      var _data=this.maxGdDataList;
      if(_searchDataVal){
         for(var i=0;i<_data.length;i++){
        var _item=_data[i];
        var _bol=this.$js.dataSearch(_searchDataVal,_item);
         if(_bol)_searchData.push(_item);
      }
      }else{
        _searchData=_data;
      }
      return _searchData;
    }
  },
  methods: {
    //撤单
    async setCancellations() {
      var self = this;
      const res = await _getcxOrder({
        uid: self.user.id,
        order_id: self.curCDorderId
      });
      if (res.data.code == 200) {
        self.$Message.success({
          content: "撤单成功",
          duration: 2
        });
          self.alertBol = false;
        self.$store.dispatch("getGdDataList");
      }
    },
    //撤单弹窗
    cdMethod(item) {
      this.curCDorderId = item.order_id;
      this.alertBol = true;
    },
       //获取小数位数
    getFloat(val, bol) {
      let _self = this;
      let _default = bol ? 0 : 1;

      let maxVal =
        String(val).split(".").length == 2
          ? val.split(".")[1].length
          : _default; // 最小变化单位
      return maxVal;
    },
    getKlineFloat(newsPrice){
        //取小数
        let  lent=this.getFloat(newsPrice)
        //小数列表
        let  floatList=[100,10,100,1000,10000,100000,1000000,10000];
        //列表长度
        let  _flentg=floatList.length-1;
        //小数大于列表长度侧默认小数位数
        lent> _flentg ? lent=floatList[_flentg]:lent=floatList[lent]
        //缓存小数信息
        localStorage.setItem('pricescale',lent)
        //修改小数引用对象
        this.$store.state.pricescale.num=lent;
     },
    //进入详情页
    goDetail(system_code,item){
      //改变交易页商品分类
      this.getKlineFloat(item.price)
      this.$store.commit('setdetialTab',item.type_id)
      this.$store.state.traViewSymboId=system_code;
      if(this.$route.name=='pending'){
         localStorage.setItem('symbol',system_code)
         this.$router.push("/trade");
      }else{
        //保存当前用户浏览的商品
        localStorage.setItem('symbol',system_code)
        //Tv事件
        const _store=this.$store.state.traViewEvent;
        //图表库更改商品
       _store.upSymbol(system_code)
       //点击图表回到顶部
        let num=10
         let distance=window.scrollY;
         let time=setInterval(()=>{
             num+=25
                 distance<= 0 ? clearInterval(time):
                 window.scrollTo(0,distance-=Math.random()*num)
            },10)
      }
    }
  },
  props: {
    searchData:{
      default:''
    }
  },

  created() {
    this.$store.getters.countGdDataList;
  }
};
</script>
